#!/usr/bin/env python
#-*- coding:utf-8 -*-

import sys
sys.path.append('../gen-py')

from cutter import Cutter
from cutter.ttypes import *

from thrift import Thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol

PORT = 9090

try:
	transport = TSocket.TSocket("localhost", PORT)
	transport = TTransport.TBufferedTransport(transport)
	protocol = TBinaryProtocol.TBinaryProtocol(transport)

	client = Cutter.Client(protocol)
	transport.open()
	client.ping()
	test_str = u"我们都是好孩子，异想天开的孩子".encode('gbk')
	words = client.process_ret_list(test_str)
	keywords = client.keyword(test_str, len(words))
	for word in keywords:
		if word.weight > 0:
			print word.word, word.weight

	transport.close()

except Thrift.TException, ex:
	print "ex:%s"%(ex.message)
